using LCL.Config;
using System;
using System.Configuration;
namespace LCL.LData
{
    public class DBOMaker
    {
        #region IDbObject
        public static IDbObject GetDbObject(DbConfigInfo conf)
        {
            return DbObject.GetDbModel(conf);
        }
        #endregion

        #region IDbScriptBuilder
        public static IDbScriptBuilder GetDbScript(DbConfigInfo conf)
        {
            return DbObject.GetDbScript(conf);
        }
        #endregion

        #region DbAccesser
        public static DbAccesser GetDbAccesser(string ConnStr, LDbType providerName)
        {
            DbAccesser db = new DbAccesser(ConnStr, providerName);
            return db;
        }
        public static DbAccesser GetDbAccesser(DbConfigInfo conf)
        {
            DbAccesser db = new DbAccesser(conf.ConnectionString, conf.DbType);
            return db;
        }
        public static bool DbLinkTest(DbAccesser _dba, LDbType _dbType)
        {
            bool flg = true;
            string sql = "SELECT getdate()";
            try
            {
                switch (_dbType)
                {
                    case LDbType.SQLServer:
                        _dba.ExecuteNonQuery(sql, null);
                        break;
                    case LDbType.Oracle:
                        sql = "select sysdate from dual";
                        _dba.ExecuteNonQuery(sql, null);
                        break;
                    case LDbType.MySQL:
                        sql = "SELECT NOW()";
                        _dba.ExecuteNonQuery(sql, null);
                        break;
                    case LDbType.MongoDB:
                        break;
                    case LDbType.SQLite:
                        _dba.ExecuteNonQuery(sql, null);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                flg = false;
                Logger.Error("DbLinkTest:", e);
            }
            return flg;
        }
        #endregion
    }
}

